package com.zhou.common.template.project.controller;

import com.zhou.base.components.bs.common.model.Response;
import com.zhou.common.template.project.service.ExcelService;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;

/**
 * @author xianfeng
 * @date 2023/12/1 19:40
 * @description:
 */
@RequiredArgsConstructor
@Slf4j
@RestController
@RequestMapping("/excel/test")
public class ExcelTestController {

    private final ExcelService excelService;

    /**
     * 下载带有下拉列表的模板
     * 1.easypoi 下拉列表超过40个后不展示问题
     * 2.excel下载设置级联下拉列表
     *
     * @param response
     * @throws Exception
     */
    @PostMapping("/downloadWithAddressList")
    @ApiOperation(value = "下载带有下拉列表的模板")
    public void downloadWithAddressList(HttpServletResponse response) throws Exception {
        excelService.downloadWithAddressList(response);
    }

    /**
     * 下载带有隐藏字段的模板
     *
     * @param response
     * @throws Exception
     */
    @PostMapping("/downloadWithDeptId")
    @ApiOperation(value = "下载带有下拉列表的模板")
    public void downloadWithDeptId(HttpServletResponse response) {
        excelService.downloadWithDeptId(response);
    }

    @PostMapping(value = "/import", headers = "Content-Type=multipart/form-data")
    @ApiOperation(value = "下载带有下拉列表的模板")
    public Response<String> importWithDeptId(@RequestParam("file") MultipartFile file) throws Exception {
        //生成测试的部门id
        String deptId = excelService.importWithDeptId(file);
        return Response.success(deptId);
    }

    /**
     * 自定义下载模板（自定义字段和下拉列表）
     *
     * @param response
     * @throws Exception
     */
    @PostMapping("/downloadCustom")
    @ApiOperation(value = "下载带有下拉列表的模板")
    public void downloadCustom(HttpServletResponse response) {
        excelService.downloadCustom(response);
    }


}
